package close.mazegame.level;

import java.util.ArrayList;

import close.mazegame.entity.Entity;
import close.mazegame.screens.Screen;

public class EntityManager<T extends Entity> {
	private ArrayList<T> entities;

	public EntityManager() {
		this.entities = new ArrayList<T>();
	}
	
	public void update(float delta){
		ArrayList<Entity> removedEntities = new ArrayList<Entity>();
		for (Entity e : entities) {
			if (e.isRemoved()) {
				removedEntities.add(e);
				e.dispose();
			} else {
				e.update(delta);
			}
		}
		entities.removeAll(removedEntities);
	}
	
	public void render(Screen screen){
		for (Entity e : entities) {
			e.render(screen);
		}
	}
	
	public void add(T entity){
		entities.add(entity);
	}
	
	public int getSize(){
		return entities.size();
	}

}
